<template>
  <div class="flexContent">
    <!-- 非标点采审核 -->
    <!-- <div class="inner"> -->
    <div class="searchBox">
      <el-form ref="form" :model="form" label-position="left" label-width="auto">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="门店名称" prop="storeId">
                  <el-select @click.native="getShopEasy" v-model="form.storeId" placeholder="请选择门店名称" style="width: 95%"
                    filterable clearable popper-class="eloption">
                    <el-option v-for="item in shopLists" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="审核状态" prop="status">
                  <el-select v-model="form.status" placeholder="请选择审核状态" style="width: 95%" clearable>
                    <el-option label="未审核" value="0" />
                    <el-option label="审核通过" value="1" />
                    <el-option label="审核拒绝" value="2" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="10" :xl="10">
                <el-form-item label="下单时间" prop="date">
                  <el-date-picker v-model="form.date" clearable type="daterange" unlink-panels range-separator="-"
                    start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width: 95%" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchList" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="resetForm('form')" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1" align="center"
          style="width: 100%" height="100%" size="medium" :row-config="{ isHover: true }"
          :scroll-y="{ enabled: true, gt: 21 }">
          <vxe-column type="seq" title="序号" width="80" />
          <vxe-column width="100" field="storeNumber" title="门店编号" />
          <vxe-column field="storeName" :min-width="elTableAdaptationWidth('storeName', tableData)" title="门店名称" />
          <vxe-column :min-width="elTableAdaptationWidth('number', tableData)" field="number" title="订单编号" />
          <vxe-column field="totalMoney" title="订货总额(元)" min-width="150" />
          <vxe-column field="storeAddress" title="门店地址" :min-width="elTableAdaptationWidth('storeAddress', tableData)" />
          <vxe-column field="orderTime" title="下单时间" min-width="150">
            <template slot-scope="{ row }">
              <span>{{ row.orderTime | parseTime }}</span>
            </template>
          </vxe-column>
          <vxe-column field="status" title="审核状态" width="100">
            <template slot-scope="{ row }">
              <el-tag v-if="row.status === '0'" type="info" size="small">未审核</el-tag>
              <el-tag v-if="row.status === '1'" size="small">审核通过</el-tag>
              <el-tag v-if="row.status === '2'" type="danger" size="small">审核拒绝</el-tag>
            </template>
          </vxe-column>

          <vxe-column fixed="right" title="操作" width="150"
            v-if="$showFn(['goodsexamine_detail', 'goodsexamine_examine'])">
            <template slot-scope="{ row }">
              <el-button type="text" @click="toDetailOrExamine(row, '0')" v-has="'goodsexamine_detail'">详情</el-button>
              <el-button v-if="row.status == '0'" type="text" @click="toDetailOrExamine(row, '1')"
                v-has="'goodsexamine_examine'">审核</el-button>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination background :current-page.sync="page.pageNum" :page-sizes="$pageSizes"
          :page-size.sync="page.pageSize" layout="total,->, sizes, prev, pager, next, jumper" :total="page.total"
          @size-change="changePageSize" @current-change="getGenericGoodsList" />
      </div>
    </div>
    <!-- </div> -->
  </div>
</template>

<script>
import { reqGenericGoodsList } from "@/api/genericGoods";
import { getShopEasy } from "@/api/shop";
export default {
  name: "GoodsExamine",
  data() {
    return {
      shopLists: [],
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      form: {
        storeId: "",
        date: [],
        status: "",
      },
      tableData: [],
      isSearch: false,
    };
  },
  computed: {
    minDate() {
      if (this.form.date == null) {
        return "";
      }
      if (this.form.date.length > 0) {
        return this.form.date[0];
      } else {
        return "";
      }
    },
    maxDate() {
      if (this.form.date == null) {
        return "";
      }
      if (this.form.date.length > 0) {
        return this.form.date[1];
      } else {
        return "";
      }
    },
  },
  mounted() {
    // this.getShopEasy();
    this.getGenericGoodsList();
  },
  methods: {
    // 获取门店列表
    async getShopEasy() {
      const res = await getShopEasy();
      if (res.code === 200) {
        this.shopLists = res.data.store;
      }
    },
    // 获取表格数据
    async getGenericGoodsList() {
      const { pageNum, pageSize } = this.page;
      let { status, storeId } = this.form;
      let { minDate, maxDate } = this;
      if (!this.isSearch) {
        minDate = "";
        maxDate = "";
        storeId = "";
        status = undefined;
      }
      const reqObj = { pageNum, pageSize, status, minDate, maxDate, storeId };
      const res = await reqGenericGoodsList(reqObj);
      console.log(res, "list");
      if (res.code === 200) {
        this.tableData = res.data.list;
        const $table = this.$refs.xTable1
        $table.loadData(this.tableData);
        this.page.total = res.data.total;
      }
    },
    // 修改每页几条
    changePageSize() {
      this.page.pageNum = 1;
      this.getGenericGoodsList();
    },
    // 搜索
    searchList() {
      this.page.pageNum = 1;
      this.isSearch = true;
      this.getGenericGoodsList();
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.page.pageNum = 1;
      this.page.pageSize = 20;
      this.form.date = [];
      this.isSearch = false;
      this.getGenericGoodsList();
    },
    toDetailOrExamine(row, isDetail) {
      if (isDetail == '1') {
        this.$router.push({
          path: "goodsExamineDetail",
          query: { isDetail: '1', id: row.id },
        });
      } else {
        this.$router.push({
          path: "toGoodsExamine",
          query: { isDetail: '0', id: row.id },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
